package cn.com.zhuxulin.android.demos.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import cn.com.zhuxulin.android.demos.R;

public class Main extends Activity {
	private ListView listView = null;
	private SimpleAdapter listAdapter = null;
	private ArrayList<HashMap<String, String>> listValues = null;
	private HashMap<String, String> demosLists = null;
	private HashMap<String, String> map = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		listView = (ListView) findViewById(R.id.list);
		map = null;
		listValues = new ArrayList<HashMap<String, String>>();
		demosLists = new HashMap<String, String>();
		demosLists.put("AlertDialog",
				"cn.com.zhuxulin.android.demos.ALERT_DIALOG");
		demosLists.put("Location", "cn.com.zhuxulin.android.demos.LOCATION");
		demosLists.put("UseArray", "cn.com.zhuxulin.android.demos.USEARRAY");
		demosLists.put("TelephonyManager",
				"cn.com.zhuxulin.android.demos.TELEPHONYMANAGER");
		demosLists.put("OpenSettings",
				"cn.com.zhuxulin.android.demos.OPENSETTINGS");
		demosLists.put("BuildVersion",
				"cn.com.zhuxulin.android.demos.BUILDVERSION");
		demosLists.put("SharedPreferences",
				"cn.com.zhuxulin.android.demos.SHAREDPREFERENCES");
		demosLists.put("SendMsg",
				"cn.com.zhuxulin.android.demos.SENDMSG");
		demosLists.put("Notification",
				"cn.com.zhuxulin.android.demos.NOTIFICATION");
		/**
		 * Iterator a map
		 */
		for (Iterator<Map.Entry<String, String>> it = demosLists.entrySet()
				.iterator(); it.hasNext();) {
			Map.Entry<String, String> e = (Map.Entry<String, String>) it.next();
			map = new HashMap<String, String>();
			map.put("DemosID", e.getKey());
			map.put("intent", e.getValue());
			listValues.add(map);
		}
	}

	@Override
	public void onStart() {
		super.onStart();
		listAdapter = new SimpleAdapter(this, listValues,
				R.layout.activity_list_item, new String[] { "DemosID" },
				new int[] { R.id.activity });
		listView.setAdapter(listAdapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> adapterView, View view,
					int which, long arg3) {
				// TODO When items clicked,start a activity
				/**
				 * Start a Activity with a Intent that set a action
				 */
				startActivity(new Intent(listValues.get(which).get("intent")));
				/**
				 * Start a Activity with a Intent that use a class
				 */
				// startActivity(new
				// Intent(getApplicationContext(),AlertDialogDemos.class));
			}
		});
	}
}